#include <algorithm>
#include <cstdio>

const int N = 10, inf = 0x3f3f3f3f;
int n, m, a[N][N], b[N][N], f[1 << (N << 1)];
bool vis[1 << (N << 1)];

int dfs(int state, bool per) {
  if (vis[state]) return f[state];
  f[state] = -inf;
  for (int i = 0, row = n, col = 0; i < n + m - 1; ++i) {
    if ((state >> i) & 1)
      --row;
    else
      ++col;
    if (((state >> i) & 3) == 1) {
      if (per)
        f[state] = std::max(f[state], -dfs(state ^ (3 << i), !per) + a[row][col]);
      else
        f[state] = std::max(f[state], -dfs(state ^ (3 << i), !per) + b[row][col]);
    }
  }
  vis[state] = true;
  return f[state];
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P4363 [九省联考2018]一双木棋chess.in", "r", stdin);
  freopen("P4363 [九省联考2018]一双木棋chess.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      scanf("%d", &b[i][j]);
    }
  }
  vis[((1 << n) - 1) << m] = true;
  printf("%d", dfs((1 << n) - 1, true));
  return 0;
}